package com.huike.web.controller.contract;

import com.huike.business.domain.TbBusiness;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.domain.BaseEntity;
import com.huike.common.core.page.PageDomain;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.exception.CustomException;
import com.huike.common.utils.DateUtils;
import com.huike.common.utils.bean.BeanUtils;
import com.huike.contract.domain.TbContract;
import com.huike.contract.domain.service.ContractService;
import com.huike.contract.domain.vo.TransferVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description TODO
 * @Author liu
 * @Date 2023-07-11 17:18
 */
@Api(tags = "合同相关管理接口")
@RequestMapping("/contract")
@RestController
@Slf4j
public class contractController extends BaseController {

    @Resource
    private ContractService contractService;

    /**
     * 新增合同接口
     * @param tbContract
     * @return
     */
    @PostMapping
    @ApiOperation("新增合同接口")
    public AjaxResult addContract(@RequestBody TbContract tbContract){
        log.info("新增合同接口:{}",tbContract);
        //调用业务新增合同
        contractService.addContract(tbContract);
        //返回数据
        return AjaxResult.success();
    }

    @PutMapping
    @ApiOperation("修改合同接口")
    public AjaxResult revampContract(TbContract tbContract){
        log.info("修改合同接口:{}",tbContract);
        contractService.revampContract(tbContract);
        return AjaxResult.success();
    }

    @GetMapping("/list")
    @ApiOperation("查询合同列表接口")
    public TableDataInfo list(TbContract tbContract){
        /*log.info("查询合同列表接口：{}",tbContract);
        List<TransferVo> list=contractService.list(tbContract);
        return AjaxResult.success(list);*/
        startPage();
        log.info("取到对象：{}",tbContract);
        List<TbContract> list = contractService.list(tbContract);
        return getDataTable(list);
    }

    @ApiOperation("商机转合同接口")
    @PutMapping("/changeContract/{id}")
    public AjaxResult changeContractId(@RequestBody TbContract tbContract, Long id){
        log.info("商机转合同接口：{}",tbContract,id);
        contractService.changeContractId(tbContract,id);
        return AjaxResult.success();
    }

}
